home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 635 < prev    next >
Internet Message Format  |  1996-08-06  |  1KB

  1. Path: solon.com!not-for-mail
  2. From: holdp@essex.ac.uk (Holden P)
  3. Newsgroups: comp.lang.c.moderated,comp.std.c
  4. Subject: Re: 'h' modifier in printf
  5. Date: 23 Mar 1996 00:48:13 -0600
  6. Organization: Essex University, England
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j06rd$82n@solutions.solon.com>
  10. References: <4i801c$455@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: knews 0.9.3
  13.  
  14. printf("Vanilla %X\nWith h  %hX\n", -1, -1);
  15.  
  16. says
  17.  
  18. Vanilla FFFFFFFF
  19. With h  FFFF
  20.  
  21. In article <4i801c$455@solutions.solon.com>,
  22.     tada@athena.mit.edu (Michael J Zehr) writes:
  23.  >
  24.  >I was recently asked a question about printf whose answer I couldn't
  25.  >determine by reading K&R2 (and alas the company doesn't have a copy of
  26.  >the standard to refer to).
  27.  >
  28.  >The "h" modifier says the corresponding argument will be printed as a
  29.  >short or unsigned short.
  30.  >
  31.  >So, given:
  32.  >
  33.  >short s;
  34.  >printf("%d", s);
  35.  >printf("%hd", s);
  36.  >
  37.  >(Assuming of course that s has been initialized at some point.)
  38.  >
  39.  >Can these two ever be different?  I'm aware of course that the short is
  40.  >widened to an int during the function call, but this preserves the
  41.  >value.
  42.  >
  43.  >
  44.  >Thanks,
  45.  >michael j zehr
  46.  
  47. -- 
  48.  
  49. Phil Holden:  AKA holdp@essex.ac.uk           Phone: +44 (0) 1206 872142
  50. ESRC Data Archive, University of Essex, Colchester, Essex C04, 3SQ, U.K
  51.